﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: CrmDeliverMajor.cs
// 作 者：代码自动生成
// 日 期：2012-4-5 15:24:37
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;

namespace ZX.CRM.Library
{
	/// <summary>
    /// 交付申请单----大课
    /// </summary>
	[Serializable]
    [Table(Name="CrmDeliverMajor")]
    [ZX.DBModule.Table("CrmDeliverMajor","ID")]
	public class CrmDeliverMajor: ZX.DBModule.BaseEntity
	{
        
        #region Business Methods 业务方法
       
		/// <summary>
        /// 主键ID
        /// </summary>
        private static PropertyInfo< Guid > IDProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< Guid >("ID"));
        [DataObjectField(true, true)]
        [Column, PK]
        public Guid ID
        {
            get { return GetProperty(IDProperty); }
            set { SetProperty(IDProperty, value); }
        }
        
		/// <summary>
        /// 编号
        /// </summary>
        private static PropertyInfo< string > CodeProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("Code"));
        [Column]
        public string Code
        {
            get { return GetProperty(CodeProperty); }
            set { SetProperty(CodeProperty, value); }
        }
		/// <summary>
        /// 订单产品ID
        /// </summary>
        private static PropertyInfo< Guid > OrderProductIDProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< Guid >("OrderProductID"));
        [Column]
        public Guid OrderProductID
        {
            get { return GetProperty(OrderProductIDProperty); }
            set { SetProperty(OrderProductIDProperty, value); }
        }
		/// <summary>
        /// 课程规划ID
        /// </summary>
        private static PropertyInfo< Guid > ProductLayoutIDProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< Guid >("ProductLayoutID"));
        [Column]
        public Guid ProductLayoutID
        {
            get { return GetProperty(ProductLayoutIDProperty); }
            set { SetProperty(ProductLayoutIDProperty, value); }
        }
		/// <summary>
        /// 谈单老师
        /// </summary>
        private static PropertyInfo< Guid > NegotiateTeachProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< Guid >("NegotiateTeach"));
        [Column]
        public Guid NegotiateTeach
        {
            get { return GetProperty(NegotiateTeachProperty); }
            set { SetProperty(NegotiateTeachProperty, value); }
        }
		/// <summary>
        /// 课中服务人
        /// </summary>
        private static PropertyInfo< Guid > ClassServerProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< Guid >("ClassServer"));
        [Column]
        public Guid ClassServer
        {
            get { return GetProperty(ClassServerProperty); }
            set { SetProperty(ClassServerProperty, value); }
        }
		/// <summary>
        /// 负责交付人
        /// </summary>
        private static PropertyInfo< Guid > ClassFrontServerProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< Guid >("ClassFrontServer"));
        [Column]
        public Guid ClassFrontServer
        {
            get { return GetProperty(ClassFrontServerProperty); }
            set { SetProperty(ClassFrontServerProperty, value); }
        }
		/// <summary>
        /// 缴款单状态
        /// </summary>
        private static PropertyInfo< Guid > DliverStateProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< Guid >("DliverState"));
        [Column]
        public Guid DliverState
        {
            get { return GetProperty(DliverStateProperty); }
            set { SetProperty(DliverStateProperty, value); }
        }
		/// <summary>
        /// 是否确认  0:否  1:是
        /// </summary>
        private static PropertyInfo< string > IsSureProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("IsSure"));
        [Column]
        public string IsSure
        {
            get { return GetProperty(IsSureProperty); }
            set { SetProperty(IsSureProperty, value); }
        }
		/// <summary>
        /// 确认人
        /// </summary>
        private static PropertyInfo< Guid > SureUserProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< Guid >("SureUser"));
        [Column]
        public Guid SureUser
        {
            get { return GetProperty(SureUserProperty); }
            set { SetProperty(SureUserProperty, value); }
        }
		/// <summary>
        /// 确认时间
        /// </summary>
        private static PropertyInfo< DateTime > SureTimeProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< DateTime >("SureTime"));
        [Column]
        public DateTime SureTime
        {
            get { return GetProperty(SureTimeProperty); }
            set { SetProperty(SureTimeProperty, value); }
        }

        /// <summary>
        /// 业绩成本归属
        /// </summary>
        private static PropertyInfo<Guid> GradeDeptIdProperty = RegisterProperty(typeof(CrmDeliverMajor), new PropertyInfo<Guid>("GradeDeptId"));
        [Column]
        public Guid GradeDeptId
        {
            get { return GetProperty(GradeDeptIdProperty); }
            set { SetProperty(GradeDeptIdProperty, value); }
        }
        /// <summary>
        /// 交付成本归属
        /// </summary>
        private static PropertyInfo<Guid> ConstDeptIdProperty = RegisterProperty(typeof(CrmDeliverMajor), new PropertyInfo<Guid>("ConstDeptId"));
        [Column]
        public Guid ConstDeptId
        {
            get { return GetProperty(ConstDeptIdProperty); }
            set { SetProperty(ConstDeptIdProperty, value); }
        }

		/// <summary>
        /// 填写人
        /// </summary>
        private static PropertyInfo< Guid > AddUserProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< Guid >("AddUser"));
        [Column]
        public Guid AddUser
        {
            get { return GetProperty(AddUserProperty); }
            set { SetProperty(AddUserProperty, value); }
        }
        /// <summary>
        /// 填写时间
        /// </summary>
        private static PropertyInfo< DateTime > AddTimeProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< DateTime >("AddTime"));
        [Column]
        public DateTime AddTime
        {
            get { return GetProperty(AddTimeProperty); }
            set { SetProperty(AddTimeProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > exp1Property = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("exp1"));
        [Column]
        public string exp1
        {
            get { return GetProperty(exp1Property); }
            set { SetProperty(exp1Property, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > exp2Property = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("exp2"));
        [Column]
        public string exp2
        {
            get { return GetProperty(exp2Property); }
            set { SetProperty(exp2Property, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > exp3Property = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("exp3"));
        [Column]
        public string exp3
        {
            get { return GetProperty(exp3Property); }
            set { SetProperty(exp3Property, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > exp4Property = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("exp4"));
        [Column]
        public string exp4
        {
            get { return GetProperty(exp4Property); }
            set { SetProperty(exp4Property, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > WorkFlowIdProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("WorkFlowId"));
        [Column]
        public string WorkFlowId
        {
            get { return GetProperty(WorkFlowIdProperty); }
            set { SetProperty(WorkFlowIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > WorkFlowInsIdProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("WorkFlowInsId"));
        [Column]
        public string WorkFlowInsId
        {
            get { return GetProperty(WorkFlowInsIdProperty); }
            set { SetProperty(WorkFlowInsIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > WorkTaskIdProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("WorkTaskId"));
        [Column]
        public string WorkTaskId
        {
            get { return GetProperty(WorkTaskIdProperty); }
            set { SetProperty(WorkTaskIdProperty, value); }
        }
		/// <summary>
        /// 
        /// </summary>
        private static PropertyInfo< string > WorkTaskInsIdProperty = RegisterProperty(typeof(CrmDeliverMajor),new PropertyInfo< string >("WorkTaskInsId"));
        [Column]
        public string WorkTaskInsId
        {
            get { return GetProperty(WorkTaskInsIdProperty); }
            set { SetProperty(WorkTaskInsIdProperty, value); }
        }
        /// <summary>
        /// 客户经理
        /// </summary>
        private static PropertyInfo<Guid> CustomerMgrProperty = RegisterProperty(typeof(CrmDeliverMajor), new PropertyInfo<Guid>("CustomerMgr"));
        [Column]
        public Guid CustomerMgr
        {
            get { return GetProperty(CustomerMgrProperty); }
            set { SetProperty(CustomerMgrProperty, value); }
        }
        /// <summary>
        /// 客户总监
        /// </summary>
        private static PropertyInfo<Guid> CustomerDirectorProperty = RegisterProperty(typeof(CrmDeliverMajor), new PropertyInfo<Guid>("CustomerDirector"));
        [Column]
        public Guid CustomerDirector
        {
            get { return GetProperty(CustomerDirectorProperty); }
            set { SetProperty(CustomerDirectorProperty, value); }
        }
        /// <summary>
        /// 分总
        /// </summary>
        private static PropertyInfo<Guid> CustomerManagerProperty = RegisterProperty(typeof(CrmDeliverMajor), new PropertyInfo<Guid>("CustomerManager"));
        [Column]
        public Guid CustomerManager
        {
            get { return GetProperty(CustomerManagerProperty); }
            set { SetProperty(CustomerManagerProperty, value); }
        }

        /// 
        /// </summary>
        private static PropertyInfo<string> StudentListProperty = RegisterProperty(typeof(CrmDeliverMajor), new PropertyInfo<string>("StudentList"));
        public string StudentList
        {
            get { return GetProperty(StudentListProperty); }
            set { SetProperty(StudentListProperty, value); }
        }
        #endregion
        
        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "Code");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Code", 15));
            ValidationRules.AddRule(CommonRules.StringRequired, "IsSure");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("IsSure", 1));
            ValidationRules.AddRule(CommonRules.StringRequired, "exp1");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("exp1", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "exp2");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("exp2", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "exp3");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("exp3", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "exp4");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("exp4", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkFlowId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkFlowId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkFlowInsId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkFlowInsId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkTaskId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkTaskId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkTaskInsId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkTaskInsId", 50));
            //base.AddBusinessRules();
        }
        #endregion
        
        #region Factory Methods 工厂方法

        public CrmDeliverMajor(){}

        public static CrmDeliverMajor New()
        {
            return DataPortal.Create< CrmDeliverMajor>();
        }
        public static CrmDeliverMajor Get(Guid ID)
        {
            return DataPortal.Fetch< CrmDeliverMajor>(new SingleLazyCriteria< CrmDeliverMajor, Guid>(ID, false));
        }
        public static void Delete(Guid ID)
        {
            DataPortal.Delete(ID);
        }

        //public override CrmDeliverMajor Save()
        //{
            //return base.Save();
        //}
        #endregion
		
		#region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(Guid ID)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
             using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("ID").Equal(ID);
                var data = db.Select< CrmDeliverMajor>(q)[0];
                LoadProperty(IDProperty, data.ID);
                LoadProperty(CodeProperty, data.Code);
                LoadProperty(OrderProductIDProperty, data.OrderProductID);
                LoadProperty(ProductLayoutIDProperty, data.ProductLayoutID);
                LoadProperty(NegotiateTeachProperty, data.NegotiateTeach);
                LoadProperty(ClassServerProperty, data.ClassServer);
                LoadProperty(ClassFrontServerProperty, data.ClassFrontServer);
                LoadProperty(DliverStateProperty, data.DliverState);
                LoadProperty(IsSureProperty, data.IsSure);
                LoadProperty(SureUserProperty, data.SureUser);
                LoadProperty(SureTimeProperty, data.SureTime);
                LoadProperty(AddUserProperty, data.AddUser);
                LoadProperty(AddTimeProperty, data.AddTime);
                LoadProperty(exp1Property, data.exp1);
                LoadProperty(exp2Property, data.exp2);
                LoadProperty(exp3Property, data.exp3);
                LoadProperty(exp4Property, data.exp4);
                LoadProperty(WorkFlowIdProperty, data.WorkFlowId);
                LoadProperty(WorkFlowInsIdProperty, data.WorkFlowInsId);
                LoadProperty(WorkTaskIdProperty, data.WorkTaskId);
                LoadProperty(WorkTaskInsIdProperty, data.WorkTaskInsId);
                LoadProperty(CustomerMgrProperty, data.CustomerMgr);
                LoadProperty(CustomerDirectorProperty, data.CustomerDirector);
                LoadProperty(CustomerManagerProperty, data.CustomerManager);
                LoadProperty(StudentListProperty, data.StudentList);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(IDProperty);
        }
        #endregion

	}
}

